package com.lin.subject.domain.handler.subject;

import com.lin.subject.commom.enums.IsDeletedFlagEnum;
import com.lin.subject.commom.enums.SubjectInfoTypeEnum;
import com.lin.subject.domain.convert.BriefSubjectConverter;
import com.lin.subject.domain.entity.SubjectAnswerBO;
import com.lin.subject.domain.entity.SubjectInfoBO;
import com.lin.subject.domain.entity.SubjectOptionBO;
import com.lin.subject.infra.basic.entity.SubjectBrief;
import com.lin.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/*
 * @Author Lin
 * @Description 简单题实现类
 * @Date 2025/2/7
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler{

    @Resource
    private SubjectBriefService subjectBriefService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    /**
     * 实际题目的插入
     *
     * @param subjectInfoBo
     */
    @Override
    public void insertSubject(SubjectInfoBO subjectInfoBo) throws Exception {

        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectInfoBo.getId().intValue());
        subjectBrief.setSubjectAnswer(subjectInfoBo.getSubjectAnswer());
        subjectBrief.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());

        subjectBriefService.insertOne(subjectBrief);
    }

    /**
     * 查询题目的选项及正确答案
     *
     * @param id
     * @return
     */
    @Override
    public SubjectOptionBO query(Long id) {
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();

        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(id.intValue());


        SubjectBrief brief = subjectBriefService.queryOneByCondition(subjectBrief);

        subjectOptionBO.setSubjectAnswer(brief.getSubjectAnswer());
        return subjectOptionBO;
    }

    /**
     * 删除题目
     *
     * @param id
     */
    @Override
    public void deleteSubject(Long id) {
        subjectBriefService.deleteSubject(id);
    }
}
